package com.qf.flash.ui.chat;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.qf.dblib.dao.entity.ChatUserBean;
import com.qf.flash.R;
import com.qf.flash.ui.home.MemberMsgActivity;
import com.qf.flash.utils.ImageLoader;
import com.qf.flashlib.adapter.BaseRViewItem;
import com.qf.flashlib.adapter.RViewHolder;

import static com.qf.flash.constant.Constant.IS_FROM_CHAT;

public class ContactItem extends BaseRViewItem<Object> {


    @Override
    public boolean isItemView(Object entity, int position) {
        return entity instanceof ChatUserBean;
    }
    @Override
    public int getItemLayout() {
        return R.layout.item_contact;
    }

    @Override
    public void convert(RViewHolder holder, Object entity, int position, int itemSize) {
        ChatUserBean chatUserBean = (ChatUserBean) entity;

        ImageView ivHead = holder.getView(R.id.iv_head);
        ImageView ivDec = holder.getView(R.id.iv_dec);
        if (chatUserBean.getSex().equals("1")) {
            holder.setImageResource(R.id.iv_sex, R.mipmap.icon_man);
        } else {
            holder.setImageResource(R.id.iv_sex, R.mipmap.icon_woman);
        }
        ImageLoader.loadCircleHead(holder.getmConvertView().getContext(), chatUserBean.getPhoto(), ivHead);
//        ImageLoader.loadFit(holder.getmConvertView().getContext(), chatUserBean.getPhotoLineImage(), ivDec);
        Glide.with(ivDec).load(chatUserBean.getPhotoLineImage()).into(ivDec);
        holder.setText(R.id.name, chatUserBean.getName());
        holder.setText(R.id.tv_level, "LV." + chatUserBean.getLevel());
        holder.getmConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MemberMsgActivity.start((Activity) holder.getmConvertView().getContext(),chatUserBean.getUid(),IS_FROM_CHAT);
            }
        });
    }
}
